import { defineStore } from 'pinia'

export const useStore = defineStore('user', {
    state() {
        return {
            //用户数据
            userInfo: JSON.parse(window.sessionStorage.getItem('userInfo') || '{}')
        }
    },
    getters: {

    },
    actions: {
        //获取用户信息
        setUserInfo(payload: any) {
            this.userInfo = payload
            //存储到浏览器本地
            window.sessionStorage.setItem('userInfo', JSON.stringify(payload))
        },
        //清除用户信息
        clearUserInfo() {
            this.userInfo = {}
            window.sessionStorage.removeItem('userInfo')
        }
    }
})